package uscdb.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import uscdb.pageModel.DataGrid;
import uscdb.pageModel.Json;
import uscdb.pageModel.PageHelper;
import uscdb.pageModel.Problem;
import uscdb.service.ProblemServiceI;

/**
 * 问题单信息控制器
 * 
 * @author SYSTEM
 *
 */
@Controller
@RequestMapping("/problemController")
public class ProblemController extends BaseController {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(ProblemController.class);

	@Autowired
	private ProblemServiceI problemService;

	/**
	 * 添加 问题单 信息
	 * 
	 * @return
	 */
	@RequestMapping("/add")
	@ResponseBody
	public Json add(Problem problem) {
		Json json = new Json();
		try {
			problemService.add(problem);
			json.setSuccess(true);
			json.setMsg("添加成功！");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			json.setMsg("系统故障，请联系管理员");
		}
		return json;
	}

	/**
	 * 修改 出差 信息
	 * 
	 * @param product
	 * @return
	 */
	@RequestMapping("/edit")
	@ResponseBody
	public Json edit(Problem problem) {
		Json json = new Json();
		try {
			problemService.edit(problem);
			json.setSuccess(true);
			json.setMsg("修改成功！");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			json.setMsg("系统故障，请联系管理员");
		}
		return json;
	}

	/**
	 * 删除 问题单 信息
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Json delete(String ids) {
		Json json = new Json();
		try {
			problemService.delete(ids);
			json.setSuccess(true);
			json.setMsg("删除成功！");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			json.setMsg("系统故障，请联系管理员");
		}
		return json;
	}

	/**
	 * 获取 数据表格
	 * 
	 * @param problem
	 * @return
	 */
	@RequestMapping("/dataGrid")
	@ResponseBody
	public DataGrid dataGrid(Problem problem, PageHelper ph) {
		return problemService.dataGrid(problem, ph);
	}
	
	/**
	 * 跳转到 mission 管理页面
	 * 
	 * @return
	 */
	@RequestMapping("/manager")
	public String manager(HttpServletRequest request) {
		return "/project/problem";
	}
	

}
